package com.longrise.android.byjk.plugins.tabthird.personal;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.common.glide.RoundCornersTransformation;
import com.longrise.common.utils.AppUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/3/6.
 * 更换背景的adapter
 */

public class ChangeSeniorDeatilAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder> {

    List<EntityBean> mList = new ArrayList<>();
    private changeSeniorDetailListener mListener;

    public ChangeSeniorDeatilAdapter() {
        super(R.layout.item_rcv_change_wall);
    }

    public void setDatas(EntityBean[] beans) {
        mList.clear();
        for (int x = 0; x < beans.length; x++) {
            mList.add(beans[x]);
        }
        setNewData(mList);
    }

    @Override
    protected void convert(final BaseViewHolder helper, EntityBean item) {
        View convertView = helper.getConvertView();
        ImageView iv = (ImageView) convertView.findViewById(R.id.item_rcv_change_wall_iv);
        ImageView iv2 = (ImageView) convertView.findViewById(R.id.item_rcv_change_wall_iv2);
        TextView tv_use = (TextView) convertView.findViewById(R.id.item_rcv_use_tv);
        TextView tv_yulan = (TextView) convertView.findViewById(R.id.item_rcv_yulan_tv);
        final String needscores = item.getString("needscores"); //所需花费的积分
        final String cdnurl = item.getString("showpicurl"); //商品图片地址
        final String backpicurl = item.getString("backpicurl"); //大图片地址
        final String lockstate = item.getString("state"); //解锁状态  1:已解锁  0：未解锁 2:正在使用
        final String goodsId = item.getString("goodsid");
        final String detailpicurl = item.getString("detailpicurl"); //预览图片
        //.placeholder
        RoundCornersTransformation transformation =
                new RoundCornersTransformation(mContext,
                        AppUtil.dip2px(4),
                        RoundCornersTransformation.CornerType.TOP);
        Glide.with(mContext)
                .load(cdnurl)
                .bitmapTransform(transformation)
                .into(iv);
        switch (lockstate) {
            case "1":  //1:已解锁
                iv2.setVisibility(View.GONE);
                tv_use.setVisibility(View.VISIBLE);
                break;
            case "2":  //2:正在使用
                iv2.setVisibility(View.VISIBLE);
                tv_use.setVisibility(View.GONE);
                break;
        }
        tv_use.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onClick(1, lockstate, goodsId, null, null, helper.getPosition());
                }
            }
        });

//        tv_yulan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mListener != null) {
//                    mListener.onClick(2, lockstate, goodsId, backpicurl, detailpicurl, helper.getPosition());
//                }
//            }
//        });

    }

    public void setOnRcvItemClickListener(changeSeniorDetailListener listener) {
        this.mListener = listener;
    }

    public interface changeSeniorDetailListener {
        void onClick(int type,String lockstate,String goodsid,
                    String imageUrl,String detailpicurl, int position);
    }
}
